package com.example.text

import android.widget.RadioButton
import androidx.core.view.get
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import com.example.text.base.BaseActivity
import com.example.text.databinding.ActivityMainBinding
import com.example.text.fg.MallFragment
import com.example.text.fg.MessageFragment
import com.example.text.fg.MineFragment
import com.example.text.fg.MotoCircleFragment
import com.example.text.fg.MotoClubJoinedFragment
import com.example.text.main.viewmodel.MainViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : BaseActivity<MainViewModel,ActivityMainBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_main

//    //自动注入
//    val mViewModel: MainViewModel by viewModels()
//
//    companion object {
//        private const val MY_CAR_FRAGMENT = "myCar"
//        private const val MOTOR_CIRCLE_FRAGMENT = "friends"
//        private const val MOTOR_CLUB_FRAGMENT = "club"
//        private const val MOTOR_CLUB_FRAGMENT_CHECKING = "club_checking"
//        private const val MOTOR_CLUB_FRAGMENT_NOT_JOINED = "club_not_joined"
//        private const val MINE_FRAGMENT = "mine"
//        private const val MALL_FRAGMENT = "mall"
//        private const val MESSAGE_FRAGMENT = "message"
//
//        const val MESSAGE_REGISTRATION_ID = "com.jczy.cyclone.MESSAGE_REGISTRATION_ID"
//    }


    override fun initView() {
        super.initView()
    (mBinding.rgBottom[1] as RadioButton).isChecked=true
    mBinding.rgBottom.setOnCheckedChangeListener { _, checkedId ->
        when (checkedId) {
            R.id.nav_motor_club -> showFragment(MotoClubJoinedFragment())
            R.id.nav_motor_circle -> showFragment(MotoCircleFragment())
            R.id.nav_motor_mall -> showFragment(MallFragment())
            R.id.nav_message -> showFragment(MessageFragment())
            R.id.nav_mine -> showFragment(MineFragment())
        }
    }
    }

    private fun showFragment(fragment: Fragment) {
        supportFragmentManager.commit {
            replace(R.id.fragment_container, fragment)
            setReorderingAllowed(true)
            // 可以添加过渡动画等
            // setCustomAnimations(...)
        }
    }
//    private val mMotoCircleFragment by lazy {
//        // MotoCircleV2Fragment()
//        //MotoCircleV3Fragment()
//        MotoCircleFragment()
//    }
//
//
//    private val mMotoClubNotJoinedFragment: Fragment by lazy {
//        if (BuildConfig.DEBUG)
//            //ClubHomeFragmentV2()
//            MotoClubJoinedFragment()
//        else
//            //MotorClubNotJoinedFragment()
//            MotoClubNotJoinedFragment()
//
//    }
//    private val mMineFragment by lazy {
//        MineFragment()
//    }
//    private val mMallFragment by lazy {
//        //MallHomeFragment()
//        MallFragment()
//    }
//
//    private val mMessageFragment by lazy {
//        MessageFragment()
//    }
//
//    //底部导航
//    private fun navToFragment(id: Int) {
//        val bt = supportFragmentManager.beginTransaction()
//        hideCurrentFragment(bt)
//        when (id) {
//            R.id.nav_motor_circle -> {
//
//                if (supportFragmentManager.findFragmentByTag(MOTOR_CIRCLE_FRAGMENT)?.isAdded != true) {
//                    bt.add(R.id.fragment_container, mMotoCircleFragment, MOTOR_CIRCLE_FRAGMENT)
//                } else {
//                    bt.show(mMotoCircleFragment)
//                }
//
//                bt.commitAllowingStateLoss()
//                //updateUnreadMessage()
//            }
//
//            R.id.nav_motor_club -> {
//
//                analysisClubFragment(bt)
//            }
//
//            R.id.nav_mine -> {
//
//
//
//                if (supportFragmentManager.findFragmentByTag(MINE_FRAGMENT)?.isAdded != true) {
//                    bt.add(R.id.fragment_container, mMineFragment, MINE_FRAGMENT)
//                } else {
//                    bt.show(mMineFragment)
//                }
//                bt.commitAllowingStateLoss()
//                //updateUnreadMessage()
//            }
//
//            R.id.nav_motor_mall -> {
//
//
//                if (supportFragmentManager.findFragmentByTag(MALL_FRAGMENT)?.isAdded != true) {
//                    bt.add(R.id.fragment_container, mMallFragment, MALL_FRAGMENT)
//                } else {
//                    bt.show(mMallFragment)
//                }
//                bt.commitAllowingStateLoss()
//                //updateUnreadMessage()
//            }
//
//            R.id.nav_message -> {
//
//                if (supportFragmentManager.findFragmentByTag(MESSAGE_FRAGMENT)?.isAdded != true) {
//                    bt.add(R.id.fragment_container, mMessageFragment, MESSAGE_FRAGMENT)
//                } else {
//                    bt.show(mMessageFragment)
//                }
//                bt.commitAllowingStateLoss()
////                if (!AuthMMKV.hasLogin()) {
////                    LoginHelper(this).jumpLogin()
////                }
//                //updateUnreadMessage()
//            }
//        }
//    }
//
//
//    /** 供子Fragment调用的方法 */
//    fun replaceClubFragment() {
//        val bt = supportFragmentManager.beginTransaction()
//        hideClubFragment(bt)
//        analysisClubFragment(bt)
//    }
//    /** 分析俱乐部Fragment */
//    private fun analysisClubFragment(bt: FragmentTransaction) {
////        if (SDataProvider.needCheckingClub) {
////            /** 检查俱乐部状态 */
////            if (supportFragmentManager.findFragmentByTag(MOTOR_CLUB_FRAGMENT_CHECKING)?.isAdded != true) {
////                bt.add(R.id.fragment_container, mMotorClubCheckingFragment, MOTOR_CLUB_FRAGMENT_CHECKING)
////            } else {
////                bt.show(mMotorClubCheckingFragment)
////            }
////        } else if (SDataProvider.hasJoinedClub && SDataProvider.autoJumpDetailWhenJoined) {
////            /** 已加入某个俱乐部 */
////            if (supportFragmentManager.findFragmentByTag(MOTOR_CLUB_FRAGMENT)?.isAdded != true) {
////                bt.add(R.id.fragment_container, mMotoClubFragment, MOTOR_CLUB_FRAGMENT)
////            } else {
////                bt.show(mMotoClubFragment)
////            }
////        } else {
//        /** 未加入任何俱乐部 */
//        if (supportFragmentManager.findFragmentByTag(MOTOR_CLUB_FRAGMENT_NOT_JOINED)?.isAdded != true) {
//            bt.add(R.id.fragment_container, mMotoClubNotJoinedFragment, MOTOR_CLUB_FRAGMENT_NOT_JOINED)
//        } else {
//            bt.show(mMotoClubNotJoinedFragment)
//        }
////        }
//        bt.commitAllowingStateLoss()
//    }
//
//    private fun hideCurrentFragment(bt: FragmentTransaction) {
//        if (supportFragmentManager.findFragmentByTag(MOTOR_CIRCLE_FRAGMENT)?.isVisible == true) {
//            bt.hide(mMotoCircleFragment)
//        }
//        hideClubFragment(bt)
//        if (supportFragmentManager.findFragmentByTag(MINE_FRAGMENT)?.isVisible == true) {
//            bt.hide(mMineFragment)
//        }
//        if (supportFragmentManager.findFragmentByTag(MALL_FRAGMENT)?.isVisible == true) {
//            bt.hide(mMallFragment)
//        }
//
//        if (supportFragmentManager.findFragmentByTag(MESSAGE_FRAGMENT)?.isVisible == true) {
//            bt.hide(mMessageFragment)
//        }
//    }
//
//    /** 隐藏俱乐部相关Fragment */
//    private fun hideClubFragment(bt: FragmentTransaction) {
////        if (supportFragmentManager.findFragmentByTag(MOTOR_CLUB_FRAGMENT_CHECKING)?.isVisible == true) {
////            bt.hide(mMotorClubCheckingFragment)
////        }
////        if (supportFragmentManager.findFragmentByTag(MOTOR_CLUB_FRAGMENT)?.isVisible == true) {
////            bt.hide(mMotoClubFragment)
////        }
//        if (supportFragmentManager.findFragmentByTag(MOTOR_CLUB_FRAGMENT_NOT_JOINED)?.isVisible == true) {
//            bt.hide(mMotoClubNotJoinedFragment)
//        }
//    }

//    private fun updateUnreadMessage() {
//        if (AuthMMKV.hasLogin())
//            mViewModel.getUnreadMessageV2()
//    }
}